package com.ting.test.algorithms.大厂刷题班;

import java.util.Stack;

public class 逆序输出栈 {

    public static void main(String[] args) {
        Stack<Integer>  stack=new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
       Stack result= reverse(stack);
    }

    private static Stack reverse(Stack<Integer> stack) {
       Integer res=process(stack);
       stack.push(res);
        return stack;
    }

    private static Integer  process(Stack<Integer> stack) {
        if(stack.isEmpty()){
            return null;
        }
        final Integer pop = stack.pop();
        Integer res=process(stack);
        if(res!=null){
            stack.push(res);
        }
        return pop;

    }
}
